home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
216_01
/
anywhere.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
24KB
|
766 lines
/***************************************************************
* *
* WHERE *
* *
* Where is a program to locate files on the PC hard disk. *
* It requires DOS 2.x or 3.x. *
* *
* The command line syntax is: *
* where [starting directory]filename.ext *
* *
* Written by Mark S. Ackerman *
* PROGRAM IS WRITTEN IN MARK WILLIAMS M W C 8 6 LANGUAGE *
* Copyright 1984, 1985 by Mark S. Ackerman. Permission is *
* granted for unlimited copies if not sold or otherwise *
* exchanged for gain. *
* PUBLISHED IN PC TECH JOURNAL - OCT '85 - VOL 3, NO. 10 *
* *
* MODIFIED FOR LATTICE C VER 2.15 BY JOHN TEICHERT NOV 85 *
* Names shortened to 8 significant characters. *
* Elimination of PTOREG() function *
* flag86 defined to return flags from intdosx() *
* Use segread to set up regs for intdosx() function. *
* Program modified to look for drive designator with colon.*
* DATE structure defined with bits high order to low order.*
* intrpt.h replaced with dos.h header file *
* rindex() function replaced with strrchr() function. *
* *
* MODIFIED FOR MICROSOFT V3 BY JOHN TEICHERT JAN 86. *
* flag86 REDEFINED to dos_result for intdosx() ax reg *
* modified to use flag in REGS structure. *
* DATE structure defined with bits low order to high order.*
* _stack will not produce large stack in ver 3.0 must use *
* link option or exemod program. *
* *
* Added Code And Became ANYWHERE JOHN TEICHERT FEB 86 *
* *
* Taking advantange of V3 access to the environment *
* string we set up the following. *
* *
* 1. An Environment String indicating what disk drives *
* you want ANYWHERE to search as follows: *
* *
* AWDISKS=d:[;d:[;d:;...d:]] *
* *
* where d: is the drive specifier for one or more *
* fixed disk(s). *
* *
* drive specifiers are searched in the order they *
* are entered. *
* *
* 2. The user can specify the environment string with *
* the use of the set command in the autoexec.bat file.*
* As an example: *
* *
* set awdisks=c:;e:;d: *
* *
* would be placed into the autoexec.bat file. *
* *
* With this modification the user has extended directory *
* capabilities by automatically searching all disk drives*
* listed in the environment string or isolated to a *
* single drive by placing a drive specifier in the *
* command line argument string. *
* *
* Be sure to use the /stack option on the link with *
* Microsoft V3 C compiler or stack problems will result *
* if many subdirectories. 8K seems to work well. *
* *
***************************************************************/
/***************************************************************
* The C header files *
* These identify library routines like printf() and int86x() *
***************************************************************/
#include <stdio.h> /* standard i/o */
#include <dos.h> /* functions for DOS interrupt calls */
/***************************************************************
* Structure for MS-DOS date and time fields *
* See pages 4-6 and 4-7 of the DOS 2.1 technical *
* reference manual for more information *
* This structure is used in the next structure definition *
***************************************************************/
struct msdos_date
{
unsigned ms_sec : 5; /* time in 2 sec. int (5 bits)*/
unsigned ms_min : 6; /* minutes (6 bits) */
unsigned ms_hour : 5; /* hours (5 bits) */
unsigned ms_day : 5; /* day of month (5 bits) */
unsigned ms_month : 4; /* month (4 bits) */
unsigned ms_year : 7; /* year since 1980 (7 bits) */
};
/***************************************************************
* Definition of DOS Disk Transfer Area (DTA) *
***************************************************************/
/***************************************************************
* Structure filled in by MS-DOS for interrupt 21 calls *
* See page 5-46 of the DOS 2.1 technical reference *
* manual for more information *
***************************************************************/
struct DTA
{
char DTA_dosinfo[21]; /* used by DOS */
char DTA_attr; /* file attribute byte */
struct msdos_date DTA_date; /* date struct. as above */
long DTA_size; /* file size */
char DTA_filename[13]; /* file name (w/o path) */
};
/***************************************************************
* Definitions of constants *
***************************************************************/
#define carry_set 0x0001 /* mask for flag register */
/* for carry bit */
#define no_type 0x00 /* no bits set on file attribute byte */
#define directory_type 0x10 /* directory file bit on file */
/* info word */
#define no_more_files 18 /* DOS return code for */
/* no more files */
#define end_of_string '\0' /* C uses a binary zero to */
/* signal end of string */
#define backslash '\\' /* the backslash character */
#define colon ':' /* Drive separator JT 11/85 */
#define semicolon ';' /* Environment string drive separator */
char *month[] = {
"Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"
};
char *time_of_day[2] = {"AM","PM"};
/***************************************************************
* Define the type "filename" *
* to be a string of 65 characters -JT *
***************************************************************/
typedef char filename[65]; /* Change to 65 -JT */
/***************************************************************
* *
* The following filename strings are used in the program: *
* *
* chk_str filename to be searched for *
* filename in the command line) *
* dir_string directory name to be searched *
* new_dstr directory name to be searched *
* on next recursive call *
* cur_str temporary string for searching *
* in a specific directory *
***************************************************************/
/***************************************************************
* Definition of any forward-referenced functions *
***************************************************************/
char *DATE();
/***************************************************************
* Global variables *
***************************************************************/
filename chk_str; /* this string "remembers" user input */
union REGS r8086; /* structure to allow access to indiv.*/
/* registers for interrupts */
struct SREGS s8086; /* structure for segment registers */
char date_str[40]; /* print output string for dates */
unsigned dos_result; /* Return code from DOS */
/**
* FOLLOWING CODE COMMENTED OUT FOR V3.0 SINCE CAN'T FIND A WAY TO DO IT
* WITH A VARIABLE.
**/
/*int _stack = 8192; Insure large stack to support */
/* recursion in look routine */
/***************************************************************
* MAIN() -- the beginning of the code *
***************************************************************/
main( argc, argv, envp )
int argc;
char *argv[];
char *envp[]; /* Version 3 pointer to environ */
{
/**
* External function
**/
char *strrchr(); /* Lattice function which searches */
/* for